import { _decorator, Component, instantiate, tween, Vec3, Node, Prefab, random} from 'cc';
import { Layer } from "./StaticDefine";
import { HandCard } from "./HandCard";
import { CpgCard } from './CpgCard';

const { ccclass, property } = _decorator;

@ccclass('Player') // 用 @ccclass 声明类为 Cocos 组件
export class Player extends Component {

    @property index: number = -1;
    @property(HandCard) handCard!: HandCard;
    @property(CpgCard) cpgCard!: CpgCard;

    public mySeat: boolean = false;

    public cardIDs: number[] = [];
    public exileCard: Node | null = null;

    onLoad(): void {
    }

    onReset() {
        this.handCard.onReset();
        this.cpgCard.onReset();
    }

    public setMySeat() {
        this.mySeat = true;
        this.handCard.node.layer = Layer.HANDCARD;
        this.handCard.mySeat = true;
        
        this.cpgCard.mySeat = true;
        this.cpgCard.takeAway();
    }

    public getHandCard() {
        return this.handCard;
    }

    public getCpg() {
        return this.cpgCard;
    }

    public onAction(type:number) {
        if( this.cpgCard.notFullyCollected())
        {
            this.handCard.cardIDs.splice(0, 3);
            this.handCard.syncDate();

            this.cpgCard.onAction();
        }
    }

    public gameStart() {
        this.handCard.startCard();
    }

    public clickCard(index: number) {
        this.handCard.selectCard(index);
    }

}